<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    
      // Load the Visualization API and the bar chart package.
      google.load('visualization', '1', {'packages':['annotatedtimeline']});
      
      // Set a callback to run when the Google Visualization API is loaded.
      google.setOnLoadCallback(initializeData);

      /**
       * Once visualization API is loaded, retrieve data and set callback to run once retrieved.
       */
      function initializeData() {
        // Get all of the dorm data from the spreadsheet.
        var dormDataURL = 'http://spreadsheets.google.com/tq?range=A3:AD17&headers=-1&key=0An9ynmXUoikYdDBmWkxiSnAwWTFrLVJTY2R5UnJVUmc&gid=0';
        var dormDataQuery = new google.visualization.Query(dormDataURL);
        // Update the chart once every 30 seconds.
        dormDataQuery.setRefreshInterval(30);
        // Set a callback to run when the dorm data has been retrieved.
        dormDataQuery.send(displayDormData);
      }

      
      /**
       * Once data is available, create view to display.
       */
      function displayDormData(response) {
        // Process errors, if any.
        if (response.isError()) {
            alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
            return;
        }
        
        // Get the ilima 3 - 4 data.
        var data = response.getDataTable();
        // Format the energy timestamp column. 
        var formatter = new google.visualization.DateFormat({formatType: 'short'});
        formatter.format(data, 1);
        
        // Create the view that is just the total dorm energy data.
        var view = new google.visualization.DataView(data);
        view.setColumns([0, 1]);
        view.setRows(0,14);
        var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
        chart.draw(view, {allowRedraw: true, displayRangeSelector: false, displayZoomButtons: false});
        // Print out the timestamp for Ilima-dorm wide energy to give a sense for the last update.
        document.getElementById('chart_timestamp_div').innerHTML = data.getFormattedValue(13, 0);                          
      }

    </script>
  </head>

  <body>
    <h3>Ilima Floors 3 - 4</h3>
    <div id='chart_div' style='width: 700px; height: 240px;'><img src="http://www.google.com/ig/images/spinner.gif"/></div>
    <div style='margin-left: 90px' id="chart_timestamp_div"><img src="http://www.google.com/ig/images/spinner.gif"/></div>
  </body>
</html>

